Stepping outside Visual Studio IDE [Part 1 of 2] with Eclipse
Posted
by mbcrump
on Geeks with Blogs
See other posts from Geeks with Blogs
or by mbcrump
Published on Wed, 19 May 2010 06:38:37 GMT
Indexed on
2010/05/19
13:40 UTC
Read the original article
Hit count: 316
“If you're walking down the right path and you're willing to keep walking, eventually you'll make progress." – Barack Obama
In my quest to become a better programmer, I’ve decided to start the process of learning Java. I will be primary using the Eclipse Language IDE. I will not bore you with the history just what is needed for a .NET developer to get up and running. I will provide links, screenshots and a few brief code tutorials.
Links to documentation.
Links to binaries.
Eclipse IDE for Java EE Developers the Galileo Package (based on Eclipse 3.5 SR2)
Sun Developer Network – Java Eclipse officially recommends Java version 5 (also known as 1.5), although many Eclipse users use the newer version 6 (1.6).
That's it, nothing more is required except to compile and run java.
Installation
Unzip the Eclipse IDE for Java EE Developers and double click the file named Eclipse.exe. You will probably want to create a link for it on your desktop. Once, it’s installed and launched you will have to select a workspace. Just accept the defaults and you will see the following:
Lets go ahead and write a simple program.
To write a "Hello World" program follow these steps:
- Start Eclipse.
- Create a new Java Project:
- File->New->Project.
- Select "Java" in the category list.
- Select "Java Project" in the project list. Click "Next".
- Enter a project name into the Project name field, for example, "
HW Project
". - Click "Finish" Allow it to open the Java perspective
- Create a new Java class:
- Click the "Create a Java Class" button in the toolbar. (This is the icon below "Run" and "Window" with a tooltip that says "New Java Class.")
- Enter "
HW
" into the Name field. - Click the checkbox indicating that you would like Eclipse to create a "
public static void main(String[] args)
" method. - Click "Finish".
- A Java editor for
HW.java
will open. In the main method enter the following line.System.out.println("This is my first java program and btw Hello World");
- Save using ctrl-s. This automatically compiles
HW.java
. - Click the "Run" button in the toolbar (looks like a VCR play button).
- You will be prompted to create a Launch configuration. Select "Java Application" and click "New".
- Click "Run" to run the Hello World program. The console will open and display "This is my first java program and btw Hello World".
You now have your first java program, lets go ahead and make an applet. Since you already have the HW.java open, click inside the window and remove all code. Now copy/paste the following code snippet.
Java Code Snippet for an applet.
1: import java.applet.Applet;
2: import java.awt.Graphics;
3: import java.awt.Color;
4:
5: @SuppressWarnings("serial")
6: public class HelloWorld extends Applet{
7:
8: String text = "I'm a simple applet";
9:
10: public void init() {
11: text = "I'm a simple applet";
12: setBackground(Color.GREEN);
13: }
14:
15: public void start() {
16: System.out.println("starting...");
17: }
18:
19: public void stop() {
20: System.out.println("stopping...");
21: }
22:
23: public void destroy() {
24: System.out.println("preparing to unload...");
25: }
26:
27: public void paint(Graphics g){
28: System.out.println("Paint");
29: g.setColor(Color.blue);
30: g.drawRect(0, 0,
31: getSize().width -1,
32: getSize().height -1);
33: g.setColor(Color.black);
34: g.drawString(text, 15, 25);
35: }
36: }
The Eclipse IDE should look like
Click "Run" to run the Hello World applet. Now, lets test our new java applet. So, navigate over to your workspace for example:
“C:\Users\mbcrump\workspace\HW Project\bin” and you should see 2 files.
HW.class
java.policy.applet
Create a HTML page with the following code:
1: <HTML>
2: <BODY>
3: <APPLET CODE=HW.class WIDTH=200 HEIGHT=100>
4: </APPLET>
5: </BODY>
6: </HTML>
Open, the HTML page in Firefox or IE and you will see your applet running.
I hope this brief look at the Eclipse IDE helps someone get acquainted with Java Development. Even if your full time gig is with .NET, it will not hurt to have another language in your tool belt.
As always, I welcome any suggestions or comments.
© Geeks with Blogs or respective owner